﻿using System;
using System.Web.UI;
using mojoPortal.Web.RS.SBM.AppCode.Lib;


namespace mojoPortal.Web.RS.SBM.Controls
{
    public partial class LocationHeaderControl : RSBaseUserControl
    {

        public int LocationId 
        {
            get { return lblLocationId.Text == "" ? 0 : Convert.ToInt32(lblLocationId.Text); }
        }
        public string LocationFullAddress 
        {
            get { return lblLocationFullAddress.Text.Trim(); }
        }

        
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!Page.IsPostBack)
            {
                if (Request.RawUrl.Contains("RSLocationHistoryCalls.aspx"))
                    lnkLocationHistory.Visible = false;
                if (Request.RawUrl.Contains("RSManageContact.aspx"))
                    lnkLocationHistory.Visible = false;
            }
        }
        public void LoadLocationHeader(int companyid, int locationid, bool displayHistory = true, bool enableMapIt = true)
        {
            
            lblLocationFullAddress.Text = RSSBMCommonFunctions.GetLocationFullAddressByID(companyid, locationid);
            lblLocationId.Text = locationid.ToString();

            if (!displayHistory)
                lnkLocationHistory.Visible = false;
            if (!enableMapIt)
                lnkMapIt.Visible = false;
        }
        protected void lnkMapIt_Click(object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            int companyid = userIdentity.RSCompanyId;
            int locationid = 0;
            if (lblLocationId.Text.Length > 0)
                locationid = Convert.ToInt32(lblLocationId.Text);
            if (companyid > 0 && locationid > 0)
                ucModalViewMapControl.ShowMapDataByLocationID(companyid, locationid);
        }
        protected void lnkLocationHistory_Click(object sender, EventArgs e)
        {
            int locationid = 0;
            if (lblLocationId.Text.Length > 0)
                locationid = Convert.ToInt32(lblLocationId.Text);
            Response.Redirect("~/RS/SBM/RSLocationHistoryCalls.aspx?locationid=" + locationid);
        }
    }
}